package workexp.zookeeper;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryNTimes;

/**
 * @author zhukai
 * 
 */
public class ZKSingleClient {
	private static final ZooKeeperUrlService service= new ZooKeeperUrlServiceImpl(); 
	
	public static CuratorFramework getClient() {
		String zkUrl = service.getUrl();
		CuratorFramework client = CuratorFrameworkFactory.builder()
				.connectString(zkUrl)
				.retryPolicy(new RetryNTimes(5, 1000))
				.connectionTimeoutMs(5000)		
				.build();
		client.getConnectionStateListenable().addListener(new retryListener());
		client.start();
		return client;
	}
}
